Use case: SDIO configuration and card identification sequence

The card identification function performs communication with the SDIO card and extracts the card’s key information, needed before applying the user configurations and starting operation. Users can provide a custom identification sequence to handle device-specific requirements or vendor extensions that differ from the default flow.

HAL1

HAL2

In HAL1 (Callback Registration): User used to register his custom card identification function using HAL_SDIO_RegisterIdentifyCardCallback(). The driver then executed this callback internally during the HAL_SDIO_Init() function. If not registered, the driver used the default identification sequence.

In HAL2 (Direct Parameter): The sequence is changed, there is no registration step and the user should pass the identification function directly as the third argument to HAL_SDIO_SetConfig(). Passing NULL instructs the driver to use the default identification sequence.

@startuml
hide footbox
participant "User Application" as part1
participant "HAL SDIO" as part2
activate part1
activate part2

group Identify card callback registration
alt USER_SDIO_USE_CUSTOM_IDENTIFY defined
        part1 -> part2 : HAL_SDIO_RegisterIdentifyCardCallback(&hsdio, USER_SDIO_IdentifyCard)
        part2 --> part1
else Default identify
        part1 --> part1
        note right
            Do nothing to use the default implementation
        end note
end
end

group Initialization & Configuration
        part1->part2 : HAL_SDIO_Init(&hsdio)
        part2-->part1 : HAL Status
end
@enduml

Code Snippet

HAL1

HAL2

hsdio.Instance = SDMMC1;
hsdio.Init = user_sdio_config;

/* Register custom card identification function if needed */
#if defined(USER_SDIO_USE_CUSTOM_IDENTIFY)
/* Register custom card identification function */
HAL_SDIO_RegisterIdentifyCardCallback(&hsdio,
                                      USER_SDIO_IdentifyCard);

#else
/* Do nothing; use default card identification */
#endif

/* Continue with SDIO initialization and configuration */
HAL_SDIO_Init(&hsdio);


HAL_StatusTypeDef USER_SDIO_IdentifyCard(SDIO_HandleTypeDef *hsdio)
{
    /* Custom card identification sequence */
    .
    ..
    ...
    return HAL_OK;
}
/* Perform SDIO driver initialization */
HAL_SDIO_Init(&hsdio, HAL_SDIO_CARD_1);

/* Perform SDIO configuration */
#if defined(USER_SDIO_USE_CUSTOM_IDENTIFY)
/* Provide custom identify card function */
HAL_SDIO_SetConfig(&hsdio,
                   &user_sdio_config,
                   USER_SDIO_IdentifyCard);
#else
/* Pass NULL as third param; use default card identification */
HAL_SDIO_SetConfig(&hsdio, &user_sdio_config, NULL);
#endif




hal_status_t USER_SDIO_IdentifyCard(hal_sdio_handle_t *hsdio)
{
    /* Custom card identification sequence */
    .
    ..
    ...
    return HAL_OK;
}